﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace StorageManage.Common
{
    public class MyCompare : Comparer<string>
    {

        public override int Compare(string o1, string o2)
        {
            //string o1 = org1.Xuhao;
            //string o2 = org2.Xuhao;
            string[] arr1 = new string[2];
            string[] arr2 = new string[2];
            char[] arr = {'.'};
            if (o1 != null && o1 != "")
            {
                if (o1.Split('.').Count() >= 2)
                {
                    arr1 = o1.Split(arr, 2);
                }
                else if (!o1.Contains('.'))
                {

                    arr1[0] = o1;
                    arr1[1] = "0";
                }
            }
            else
            {
                arr1[0] = "0";
                arr1[1] = "0";
            }

            if (o2 != null && o2 != "")
            {
                if (o2.Split('.').Count() >= 2)
                {
                    arr2 = o2.Split(arr, 2);
                }
                else if (!o2.Contains('.'))
                {

                    arr2[0] = o2;
                    arr2[1] = "0";
                }
            }
            else
            {
                arr2[0] = "0";
                arr2[1] = "0";
            }
            if (Convert.ToInt32(arr1[0]) != Convert.ToInt32(arr2[0]))
            {
                return Convert.ToInt32(arr1[0]) - Convert.ToInt32(arr2[0]);
            }
            else
            {
                
                return Compare(arr1[1], arr2[1]);
            }
        }
    }
}